<!--
 * @Author: lvli 1746254597@qq.com
 * @Date: 2022-06-09 15:44:44
 * @LastEditors: lvli 1746254597@qq.com
 * @LastEditTime: 2022-06-09 17:10:16
 * @FilePath: \fsvue_user\login.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="css/public.css" />
	<link rel="stylesheet" type="text/css" href="css/login.css" />
	<link rel="stylesheet" type="text/css" href="css/mygrxx.css" />
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script src="js/public.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" src="js/axios.min.js"></script>
	<script type="text/javascript">

		function login() {
			var utele = document.getElementById("utele").value;
			var upwd = document.getElementById('upwd').value;
			if (utele === "" || upwd === "") {
				console.log("用户名或密码不能为空");
			} else {
				//调用 ajax
				axios.get('http://localhost:8088/users/login', {
					params: {
						'utele': utele,
						'upwd': upwd
					}
				}).then(res => {
					var status = -1;
					var uname = res.data.data.uname;
					var utele = res.data.data.utele;
					var umoney = res.data.data.umoney;
					var uid = res.data.data.uid;
					var utype = res.data.data.utype;
					if (res.data.status == '0') {
						status = 0;
						window.localStorage.setItem('uname', uname);
						window.localStorage.setItem('utele', utele);
						window.localStorage.setItem('uid', uid);
						window.localStorage.setItem('umoney', umoney);
						window.localStorage.setItem('status', status);
						window.localStorage.setItem('utype', utype);
						window.location.href = "mygxin.html";
						alert("登陆成功");
					} else {
						alert("登录失败");
					}
				})
					.catch(error => {
						if (error.request || error.response) {
							alert("账号或密码错误");
						}
					});
			};
		}
		function forget1() {
			$("#mask").show();
			$(".bj").show();
		}
		function forgetPass() {
			var utele = document.getElementById("utel").value;
			var uname = document.getElementById("uname").value;
			var upwd1 = document.getElementById("upwd1").value;
			var upass = document.getElementById("upass").value;
			if (utele === "") {
				console.log("电话不能为空");
			} else if (uname === "") {
				console.log("用户名不能为空");
			} else if (upwd1 === "") {
				console.log("新密码不能为空");
			} else if (upass === "") {
				console.log("确认密码不能为空");
			} else if (upwd1 !== upass) {
				alert("两次密码不一致");
			}
			else {
				axios.get("http://localhost:8088/users/forgetPass", {
					params: {
						'uname': uname,
						'utele': utele,
						'upwd': upwd1
					}
				})
					.then(res => {
						console.log(res.data);
						if (res.data === true) {
							window.location.href = "login.html";
							alert("修改成功");
						} else {
							alert("修改失败")
						}
					});
			}
		}
		function hidden1() {
			$("#mask").hide();
			$(".bj").hide();
			$(".avatar").hide();
		}
	</script>
</head>

<body>
	<!-------------------login-------------------------->
	<div class="login">
		<form method="Get">
			<h1 style="padding-bottom: 0px;"><img style="width: 240px;height: 79px;" src="img/temp/logo.png"></h1>
			<p></p>
			<div class="msg-warn hide"><b></b>公共场所不建议自动登录，以防账号丢失</div>
			<p><input type="text" id="utele" name="utele" value="" placeholder="手机号"></p>
			<p><input type="password" id="upwd" name="upwd" value="" placeholder="密码"></p>
			<p><input style="width:280px;background: #C10000;font-size: 20px;border:none;color:#fff;" type="button"
					name="" value="登  录" onclick="login()"></p>
			<p class="txt"><a class="" href="reg.html">免费注册</a><a onclick="forget1()">忘记密码？</a></p>
		</form>
		<!--遮罩-->
		<div id="mask"></div>
		<!--编辑弹框-->
		<div class="bj" style="width: 0;padding:0">
			<form action="#" method="get">
				<h3>忘记密码，请填写下面资料</h3>
				<p><label>姓名：</label><input type="text" id="uname" value="" /></p>
				<p><label>电话：</label><input type="text" id="utel" value="" /></p>
				<p><label>新密码：</label><input type="password" id="upwd1" value="" /></p>
				<p><label>确认密码：</label><input type="password" id="upass" value="" /></p>
				<div class="bc">
					<input type="button" value="保存" onclick="forgetPass()" />
					<input type="button" value="取消" onclick="hidden1()" />
				</div>
			</form>
		</div>
	</div>
	<div class="" id="result"></div>
</body>

</html>